package de.jmda.core.util.xl;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;

import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;

import de.jmda.core.util.xl.Util;

public class JUTUtil
{
	@Test
	public void testWorkbook() throws IOException
	{
		Workbook workbook = Util.workbook("doc/test.xlsx");

		assertNotNull("workbook is null", workbook);
	}

	@Test
	public void testRowCountAt0() throws IOException
	{
		Workbook workbook = Util.workbook("doc/test.xlsx");

		Sheet sheet = workbook.getSheetAt(0);

		assertEquals("wrong row count", 2, Util.rowCount(sheet));
	}

	@Test
	public void testColCountAt0() throws IOException
	{
		Workbook workbook = Util.workbook("doc/test.xlsx");

		Sheet sheet = workbook.getSheetAt(0);

		assertEquals("wrong col count", 2, Util.colCount(sheet));
	}

	@Test
	public void testRowCountAt1() throws IOException
	{
		Workbook workbook = Util.workbook("doc/test.xlsx");

		Sheet sheet = workbook.getSheetAt(1);

		assertEquals("wrong row count", 4, Util.rowCount(sheet));
	}

	@Test
	public void testColCountAt1() throws IOException
	{
		Workbook workbook = Util.workbook("doc/test.xlsx");

		Sheet sheet = workbook.getSheetAt(1);

		assertEquals("wrong col count", 4, Util.colCount(sheet));
	}

	@Test
	public void testRowCountAt2() throws IOException
	{
		Workbook workbook = Util.workbook("doc/test.xlsx");

		Sheet sheet = workbook.getSheetAt(2);

		assertEquals("wrong row count", 3, Util.rowCount(sheet));
	}

	@Test
	public void testColCountAt2() throws IOException
	{
		Workbook workbook = Util.workbook("doc/test.xlsx");

		Sheet sheet = workbook.getSheetAt(2);

		assertEquals("wrong col count", 2, Util.colCount(sheet));
	}
}